<%--
  Created by IntelliJ IDEA.
  User: 10330
  Date: 2021/7/7
  Time: 16:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<script>
    function showCart(){
        $("#cartModal").modal('show');
        $("#cartTitle").html("我的购物车");
        if('${sessionScope.cartGoodsList}' === ''){
            $("#cart_msg").hide();
            $("#cartBody").html("<h3>目前购物车为空，快去购物吧</h3>");
        }else{
            $("#cart_tab").show();
        }
    }

    function deleteCartGoods(id){
        $('#'+id+'goods').hide();
        $.post("${pageContext.request.contextPath}/cart?action=delete",{cartGoodsId:id},"json");
    }
</script>

<div class="modal fade" id="cartModal" role="dialog" aria-hidden="true" aria-labelledby="myModalLabel" >
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="text-align: left">
            <div class="modal-header">
                <button class="close" aria-hidden="true" type="button" data-dismiss="modal">
                    ×
                </button>
                <h4 class="modal-title" id="cartTitle">
                    我的购物车
                </h4>
            </div>
            <form class="form-inline" role="form" action="" method="post">
                <div class="modal-body" id="cartBody">
                    <div id="cart_msg" style="display:none"></div>
                    <c:if test="${sessionScope.cartGoodsList!=null}">
                        <table class="table table-striped" id="cart_tab">
                            <thead>
                            <tr>
                                <th>商品图片</th>
                                <th>商品名称</th>
                                <th>商品单价</th>
                                <th>数量</th>
                                <th>小计</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="cart_tbody">
                            <c:forEach items="${sessionScope.cartGoodsList}" var="cartGoods">
                                <tr id="${cartGoods.value.goods_id}goods">
                                    <td><img style="height: 80px" src="${pageContext.request.contextPath}${cartGoods.value.goods_pic}"></td>
                                    <td>${cartGoods.value.goods_name}</td>
                                    <td>${cartGoods.value.goods_discount}</td>
                                    <td><input type="text" name="goodsSales" value="${cartGoods.value.goods_num}" size="5" readonly></td>
                                    <td>${cartGoods.value.goods_discount * cartGoods.value.goods_num}</td>
                                    <td><a href="#" onclick="deleteCartGoods(${cartGoods.value.goods_id})">删除</a></td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </c:if>

                </div>
                <div class="modal-footer">
                    <button class="btn btn-primary" type="submit" id="ok">去结算</button>
                    <button class="btn btn-default" type="button" data-dismiss="modal" onclick="location.reload()">关闭窗口</button>
                </div>
            </form>
        </div>

    </div>
</div>

